import { request } from "./request";
// JSON对象
const from={'Content-Type': 'application/json'}
// 文件
const type={'Content-Type': 'multipart/form-data'}

//登录
export function validateLogon(username,password){
  return request({
    url:'/login',
    method:'post',
    params:{
      username,password
    }
  })
}

// 获取菜单列表
export function getMenuList(){``
  return request({
    url:'/menus'
  })
}

// 获取用户列表
export function getUserList(query,pagenum,pagesize){
  return request({
    url:'/users',
    params:{
      query,pagenum,pagesize
    }
  })
}

// 更改用户状态
export function userStateChange(id,state){
  return request({
    url:`/users/${id}/state/${state}`,
    method:'put'
  })
}

// 添加用户
export function addUser(addForm){
  return request({
    url:'/users',
    method:'post',
    data:addForm
  })
}

// 获取用户信息
export function getUser(id){
  return request({
    url:`/users/${id}`,
  })
}

// 更改用户信息
export function editUser(id,email,mobile){
  return request({
    url:`/users/${id}`,
    method:'put',
    data:{email,mobile}
  })
}

// 删除用户
export function remove(id){
  return request({
    url:`/users/${id}`,
    method:'delete'
  })
}

// 获取权限列表
export function getRightsList(){
  return request({
    url:'/rights/list'
  })
}

//获取角色列表
export function getRolesList(){
  return request({
    url:'/roles'
  })
}

//删除角色指定权限
export function removeRightById(role,rightid){
  return request({
    url:`/roles/${role.id}/rights/${rightid}`,
    method:'delete'
  })
}

//获取所有权限
export function showRightDialog(){
  return request({
    url:'/rights/tree'
  })
}

//角色授权
export function allotRights(id,rids){
  return request({
    url:`/roles/${id}/rights`,
    method:'post',
    data:{rids}
  })
}

//角色列表
export function setRole(){
  return request({
    url:'/roles',
  })
}

//选择角色分配
export function saveRoleInfo(id,rid){
  return request({
    url:`/users/${id}/role`,
    method:'put',
    data:{rid}
  })
}

//获取商品分类
export function getCateList(queryInfo){
  return request({
    url:'/categories',
    params:queryInfo
  })
}

//获取父级分类的数据列表
export function getParentCateList(){
  return request({
    url:'/categories',
    params:{
      type:2,
    }
  })
}

//添加分类
export function addCate(addCateForm){
  return request({
    url:'/categories',
    method:'post',
    data:addCateForm
  })
}

//修改分类
export function editCate(id,cat_name){
  return request({
    url:`/categories/${id}`,
    method:'put',
    data:{cat_name}
  })
}

//删除分类
export function delCate(id){
  return request({
    url:`/categories/${id}`,
    method:'delete'
  })
}

//获取所有商品分类列表
export function getAllCateList(){
  return request({
    url:'/categories'
  })
}

//参数列表
export function parameterList(id,sel){
  return request({
    url:`/categories/${id}/attributes`,
    params:{
      sel
    }
  })
}

//参数列表
export function addParameter(id,attr_name,attr_sel){
  return request({
    url:`/categories/${id}/attributes`,
    method:'post',
    data:{attr_name,attr_sel}
  })
}

//修改参数
export function editParameter(id,editForm){
  return request({
    url:`/categories/${id}/attributes/${editForm.attr_id}`,
    method:'put',
    data:{
      attr_name:editForm.attr_name,
      attr_sel:editForm.attr_sel
    }
  })
}

//删除参数
export function removeParams(id,attr_id){
  return request({
    url:`/categories/${id}/attributes/${attr_id}`,
    method:'delete',
  })
}

//删除参数
export function submitEditParameters(id,row){
  return request({
    url:`/categories/${id}/attributes/${row.attr_id}`,
    method:'put',
    data:{
      attr_name:row.attr_name,
      attr_sel:row.attr_sel,
      attr_vals:row.attr_vals.join(' ')
    }
  })
}

//获取商品列表
export function getGoods(queryInfo){
  return request({
    url:'/goods',
    params:queryInfo
  })
}

//删除商品
export function removeById(id){
  return request({
    url:`/goods/${id}`,
    method:'delete'
  })
}

//添加商品
export function addGoods(form){
  return request({
    url:`/goods`,
    method:'post',
    data:form
  })
}

//提交编辑商品
export function editGoods(form){
  return request({
    url:`/goods/${form.goods_id}`,
    method:'put',
    data:{
      goods_name:form.goods_name,
      goods_price:form.goods_price,
      goods_number:form.goods_number,
      goods_weight:form.goods_weight,
      goods_cat:form.goods_id
    }
  })
}

//获取订单数据列表
export function getOrders(queryInfo){
  return request({
    url:'/orders',
    params:queryInfo
  })
}

//查看物流信息
export function showProgressBox(){
  return request({
    url:'/kuaidi/1106975712662'
  })
}

//数据统计
export function getReport(){
  return request({
    url:'/reports/type/1'
  })
}








